package com.MediaVaultTest;

import static org.junit.Assert.*;
import java.util.LinkedList;

import org.junit.Test;

import com.google.appengine.api.blobstore.BlobKey;

public class testCases {

	/*
	 * Meaningfully named tests 1 to 14, test the order by part of the sort class
	 * 
	 */
	@Test
	public void test1() {
		UserStore userStore = new UserStore("hello", 2, 3, 4);
		BlobKey blobKey = new BlobKey("key");
		Format format = new Format(blobKey, (long)123456, "fdfd");
		Media media1 = new Media(format, "abc");
		Media media2 = new Media(format, "acb");
		Media media3 = new Media(format, "fgh");
		userStore.addMediaFile(media1);
		userStore.addMediaFile(media2);
		userStore.addMediaFile(media3);
		Sort sort =new Sort(userStore.getMedia());
		LinkedList<Media> tempList = sort.sortBy("Title", "asc");
		assertEquals(tempList.getFirst().getTitle(), "abc");
	}
	
	
	@Test
	public void test2() {
		UserStore userStore = new UserStore("hey", 2, 3, 4);
		BlobKey blobKey = new BlobKey("key");
		Format format = new Format(blobKey, (long)123456, "fdfd");
		Media media1 = new Media(format, "abc");
		Media media2 = new Media(format, "acb");
		Media media3 = new Media(format, "fgh");
		userStore.addMediaFile(media1);
		userStore.addMediaFile(media2);
		userStore.addMediaFile(media3);
		Sort sort =new Sort(userStore.getMedia());
		LinkedList<Media> tempList = sort.sortBy("Title", "dsc");
		assertEquals(tempList.getLast().getTitle(), "abc");
	}
	
	@Test
	public void test3() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);        
         BlobKey blobKey = new BlobKey("key");
         Format format = new Format (blobKey, (long)123456, "fdfd");
         Media media1 = new Media(format, "abc");
         Media media2 = new Media(format, "acb");
         Media media3 = new Media(format, "fgh");
         media1.setArtist("eminem");
         media2.setArtist("david");
         media3.setArtist("curt");
         userStore.addMediaFile(media1);
         userStore.addMediaFile(media2);
         userStore.addMediaFile(media3);
         Sort sort =new Sort (userStore.getMedia());
         LinkedList<Media> tempList = sort.sortBy("Artist", "asc");
         assertEquals(tempList.getLast().getArtist(), "eminem");	
	}
	
	@Test
	public void test4() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);        
         BlobKey blobKey = new BlobKey("key");
         Format format = new Format (blobKey, (long)123456, "fdfd");
         Media media1 = new Media(format, "abc");
         Media media2 = new Media(format, "acb");
         Media media3 = new Media(format, "fgh");
         media1.setArtist("eminem");
         media2.setArtist("david");
         media3.setArtist("curt");
         userStore.addMediaFile(media1);
         userStore.addMediaFile(media2);
         userStore.addMediaFile(media3);
         Sort sort =new Sort (userStore.getMedia());
         LinkedList<Media> tempList = sort.sortBy("Artist", "asc");
         assertEquals(tempList.getFirst().getArtist(), "curt");	
	}
	
	@Test
	public void test5() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setAlbum("love");
		 media2.setAlbum("hate");
		 media3.setAlbum("envy");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Album", "asc");
		 assertEquals(tempList.getFirst().getAlbum(), "envy");
		}
	
	@Test
	public void test6() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setAlbum("love");
		 media2.setAlbum("hate");
		 media3.setAlbum("envy");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Album", "asc");
		 assertEquals(tempList.getLast().getAlbum(), "love");
		}
	
	@Test
	public void test7() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setGenre("rock");
		 media2.setGenre("classic");
		 media3.setGenre("punk");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Genre", "asc");
		 assertEquals(tempList.getFirst().getGenre(), "classic");
		}
	
	@Test
	public void test8() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setGenre("rock");
		 media2.setGenre("classic");
		 media3.setGenre("punk");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Genre", "asc");
		 assertEquals(tempList.getLast().getGenre(), "rock");
		}
	
	@Test
	public void test9() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setLanguage("english");
		 media2.setLanguage("german");
		 media3.setLanguage("french");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Language", "asc");
		 assertEquals(tempList.getLast().getLanguage(), "german");
		}
	
	@Test
	public void test10() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setLanguage("english");
		 media2.setLanguage("german");
		 media3.setLanguage("french");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Language", "asc");
		 assertEquals(tempList.getFirst().getLanguage(), "english");
		}
	
	@Test
	public void test11() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setSeries("lost");
		 media2.setSeries("prison");
		 media3.setSeries("hero");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Series", "asc");
		 assertEquals(tempList.getFirst().getSeries(), "hero");
		}
	
	@Test
	public void test12() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setSeries("lost");
		 media2.setSeries("prison");
		 media3.setSeries("hero");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Series", "asc");
		 assertEquals(tempList.getLast().getSeries(), "prison");
		}
	
	@Test
	public void test13() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setRating(4);
		 media2.setRating(2);
		 media3.setRating(3);
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort =new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Rating", "asc");
		 assertEquals(tempList.getFirst().getRating(), 2);
		}
	
	@Test
	public void test14() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setRating(4);
		 media2.setRating(2);
		 media3.setRating(3);
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.sortBy("Rating", "asc");
		 assertEquals(tempList.getLast().getRating(), 4);
		}
	
	/*
	 * Test 15 - 18
	 * Tests the getMediaOfType part of sort
	 */
	@Test
	public void test15() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setMediaType("Photo");
		 media2.setMediaType("Photo");
		 media3.setMediaType("Music");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.getMediaOfType("Photo");
		 assertEquals(tempList.size(), 2);
		}
	
	@Test
	public void test16() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setMediaType("Photo");
		 media2.setMediaType("Photo");
		 media3.setMediaType("Music");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.getMediaOfType("Music");
		 assertEquals(tempList.size(), 1);
		}
	
	@Test
	public void test17() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setMediaType("Photo");
		 media2.setMediaType("Photo");
		 media3.setMediaType("Music");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.getMediaOfType("TV");
		 assertEquals(tempList.size(), 0);
		}
	
	@Test
	public void test18() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "abc");
		 Media media2 = new Media(format, "acb");
		 Media media3 = new Media(format, "fgh");
		 media1.setMediaType("Movie");
		 media2.setMediaType("Movie");
		 media3.setMediaType("Music");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.getMediaOfType("Movie");
		 assertEquals(tempList.size(), 2);
		}
	
	/*
	 * Test 19 - 24
	 * Tests the search part of sort
	 */
	@Test
	public void test19() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "the lol bunies");
		 Media media2 = new Media(format, "lol jokes");
		 Media media3 = new Media(format, "l o l");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.search("Title", "lol");
		 assertEquals(tempList.size(), 2);
		}
	
	@Test
	public void test20() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "the lol bunies");
		 Media media2 = new Media(format, "lol jokes");
		 Media media3 = new Media(format, "l o l");
		 media1.setArtist("the lol cats");
		 media2.setArtist("l o l");
		 media3.setArtist("lol lol lol");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.search("Artist", "lol");
		 assertEquals(tempList.size(), 2);
		}
	
	@Test
	public void test21() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "the lol bunies");
		 Media media2 = new Media(format, "lol jokes");
		 Media media3 = new Media(format, "l o l");
		 media1.setAlbum("lol cats");
		 media2.setAlbum("lol lol lol");
		 media3.setAlbum("LOL");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.search("Album", "lol");
		 //Note result changed with non case senstive searches
		 assertEquals(tempList.size(), 3);
		}
	
	@Test
	public void test22() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "the lol bunies");
		 Media media2 = new Media(format, "lol jokes");
		 Media media3 = new Media(format, "l o l");
		 media1.setGenre("lol cats");
		 media2.setGenre("Luke i am your father");
		 media3.setGenre("Noooooooooooo");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.search("Genre", "lol");
		 assertEquals(tempList.size(), 1);
		}
	
	@Test
	public void test23() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "the lol bunies");
		 Media media2 = new Media(format, "lol jokes");
		 Media media3 = new Media(format, "l o l");
		 media1.setLanguage("lol cats");
		 media2.setLanguage("Luke i am your father");
		 media3.setLanguage("Noooooooooooo");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.search("Language", "lol");
		 assertEquals(tempList.size(), 1);
		}
	
	@Test
	public void test24() {
		 UserStore userStore = new UserStore ("hey", 2, 3, 4);
		 BlobKey blobKey = new BlobKey("Key");
		 Format format = new Format (blobKey, (long)123456, "fdfd");
		 Media media1 = new Media(format, "the lol bunies");
		 Media media2 = new Media(format, "lol jokes");
		 Media media3 = new Media(format, "l o l");
		 media1.setSeries("lol cats");
		 media2.setSeries("Luke i am your father");
		 media3.setSeries("Noooooooooooo");
		 userStore.addMediaFile(media1);
		 userStore.addMediaFile(media2);
		 userStore.addMediaFile(media3);
		 Sort sort = new Sort (userStore.getMedia());
		 LinkedList<Media> tempList = sort.search("Series", "lol");
		 assertEquals(tempList.size(), 1);
		}
	
	/*
	 * Tests 25  - 31 test the quota class
	 */
	@Test
	public void test25() {
		UserStore userStore = new UserStore("hello", 0, 0, 0);
		QuotaLogic quotaLogic = new QuotaLogic();
		assertEquals(quotaLogic.getMBStoreRemaining(userStore), 100);
	}
	
	@Test
	public void test26() {
		UserStore userStore = new UserStore("hello", 0, 0, 0);
		QuotaLogic quotaLogic = new QuotaLogic();
		assertEquals(quotaLogic.getMBUploadRemaining(userStore), 100);
	}
	
	@Test
	public void test27() {
		UserStore userStore = new UserStore("hello", 0, 0, 0);
		QuotaLogic quotaLogic = new QuotaLogic();
		assertEquals(quotaLogic.getMBDownloadRemaining(userStore), 100);
	}
	
	@Test
	public void test28() {
		new UserStore("hello", 0, 0, 0);
		QuotaLogic quotaLogic = new QuotaLogic();
		assertEquals(quotaLogic.getStorageQuota(), 100000000);
	}
	
	@Test
	public void test29() {
		new UserStore("hello", 0, 0, 0);
		QuotaLogic quotaLogic = new QuotaLogic();
		assertEquals(quotaLogic.getDownloadQuota(), 100000000);
	}
	
	@Test
	public void test30() {
		new UserStore("hello", 0, 0, 0);
		QuotaLogic quotaLogic = new QuotaLogic();
		assertEquals(quotaLogic.getUploadQuota(), 100000000);
	}
	
	@Test
	public void test31() {
		new UserStore("hello", 0, 0, 0);
		QuotaLogic quotaLogic = new QuotaLogic();
		assertEquals(quotaLogic.getMaxThumbnailSize(), 500000);
	}
}
